//'转发时请保留此声明信息,这段声明不并会影响你的速度!
//'**************天枫AJAX集天气\IP\多国语言翻译MP3(可同步LRC歌词显示)\万年历查询通********
//'作者:天枫
//'网站:http://www.52515.net
//'电子邮件:chenshaobo@gmail.com
//'WEB开发群：4635188　19182747
//'QQ:76994859
//'版权声明:版权所有,源代码公开,各种用途均可免费使用,但是修改后必须把修改后的文件
//'发送一份给作者.并且保留作者此版权信息
//'**********************************************************************************

function $(objID) {
  return document.getElementById(objID)
}

function $F(objID) {
  return document.getElementById(objID).value
}
 
function JsLoader(){
	this.load=function(url){
		var ss=document.getElementsByTagName("script");
		for(i=0;i<ss.length;i++){
			if(ss[i].src && ss[i].src.indexOf(url)!=-1){
				this.onsuccess();
				return;
			}
		}
		s=document.createElement("script");
		s.type="text/javascript";
		s.src=url;
		var head=document.getElementsByTagName("head")[0];
		head.appendChild(s);
		var self=this;
		s.onload=s.onreadystatechange=function(){
			if(this.readyState && this.readyState=="loading")return;
			self.onsuccess();
		}
		s.onerror=function(){
			head.removeChild(s);
			self.onfailure();
		}
	};
	this.onsuccess=function(){};
	this.onfailure=function(){};
}

function CssLoader(cssurl){
	var head=document.getElementsByTagName('HEAD').item(0);
	var style=document.createElement('link');
	style.href=cssurl;
	style.rel='stylesheet';
	style.type='text/css';
	head.appendChild(style);
}

//天枫AJAX类V1.0
var XMLHttp=function(){
	try {return new ActiveXObject("Msxml5.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Msxml4.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Msxml3.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
	try {return new XMLHttpRequest();}catch(e){}
	return null;
}

function request(url,method,parameters,loading,callback,async){
	var req=new XMLHttp();
	var url=url;
	var method=method;
	var parameters=parameters;
	var loading=loading;
	var callback=callback;
	var async=async;
	if (req!=null){
		req.onreadystatechange = function(){
			if (req.readyState==4){
				if(req.status==200){
					window.status=""
					$(loading).style.display="none";
					callback(req);
				}else{
					window.status="服务器出错,错误代码："+req.statusText
				}
			}else{
				 window.status="正在加载......"
				 $(loading).style.display="block";
			}
		}
		if (parameters=="") url=url;
		else url+="?"+parameters;
		url+=(url.indexOf("?") >= 0)?"&nowtime="+new Date().getTime():"?nowtime=" + new Date().getTime();
		if (method=='get'){
			req.open('GET',url,async);
			req.send(null);
		}else if (method=='post'){
			req.open('POST',url,async);
			req.setRequestHeader("Content-Length",parameters.length); 
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
			req.send(parameters);
		}else{
		    window.status="请至少使用一种传送方式";
		}
	}else{
		window.status="无法创建xmlhttp";
	}
}

function updater(objid,url,method,parameters,loading,async){
	var req=new XMLHttp();
	var objid=objid;
	var url=url;
	var method=method;
	var parameters=parameters;
	var loading=loading;
	var async=async;
	if (req!=null){
		req.onreadystatechange = function(){
			if (req.readyState==4){
				if(req.status==200){
					window.status=""
					$(loading).style.display="none";
					$(objid).innerHTML=req.responseText;
				}else{
					window.status="服务器出错,错误代码："+req.statusText
				}
			}else{
				 window.status="正在加载......"
				 $(loading).style.display="block";
			}
		}
		if (parameters=="") url=url;
		else url+="?"+parameters;
		url+=(url.indexOf("?") >= 0)?"&nowtime="+new Date().getTime():"?nowtime=" + new Date().getTime();
		if (method=='get'){
			req.open('GET',url,async);
			req.send(null);
		}else if (method=='post'){
			req.open('POST',url,async);
			req.setRequestHeader("Content-Length",parameters.length); 
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
			req.send(parameters);
		}else{
		    window.status="请至少使用一种传送方式";
		}
	}else{
		window.status="无法创建xmlhttp";
	}
}
